<template>
    <!-- pages/h5/index.wxml -->
  <view>
    <navbar></navbar>
    <view class="container">
      <web-view :src="src" @message="handlePostMessage"></web-view>
    </view>
  </view>
</template>

<script>
// pages/h5/index.js
const app = getApp(); // 场景url
import navbar from "@/components/navbar/navbar";
import sceneUtils from '../../utils/sceneUtils.js';
export default {
  components: {
    navbar
  },
    data() {
        return {
            src: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        let src = ''; //options.src = undefined;
        //options.scene = 'code%3D5d53b8c85d6f9%26r%3D1%26id%3D6852';

        if (options.src !== undefined) {
            src = options.src;
        } else if (options.scene !== undefined) {
            let scene = app.aj_getSceneData(options);
            src = sceneUtils.getUrl(scene);
        }

        this.setData({
            src: decodeURIComponent(src || '')
        });
        console.log('src', this.src);
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    methods: {
		// webview向外部发送消息
		handlePostMessage: function(data) {
			//data.detail {"data":[{"url":"/pages/order/index"}]}
			data = JSON.stringify(data.detail)
			// console.log("接收到消息：" + JSON.stringify(data.detail));
			let url = JSON.parse(data).data[0].url
			if(url == '/pages/order/index'){
				uni.redirectTo({
					url: '/pages/order/index'
				})
			}
		},
		// 调用 webview 内部逻辑
		// evalJs: function() {
		// 	this.$refs.webview.evalJs("document.body.style.background ='#00FF00'");
		// }
	}
};
</script>
<style lang="scss" scoped>
/* pages/h5/index.wxss */
</style>
